package com.sanda.androidcourse.chapter11;

import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.sanda.androidcourse.R;

public class WebLoadHtmlActivity extends AppCompatActivity {

    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_web_view);

        webView = findViewById(R.id.webview);

        // 启用 JavaScript
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        // HTML 字符串内容
        String htmlData = "<html>" +
                "<head><title>演示页面</title></head>" +
                "<body style='background-color:#f5f5f5; text-align:center;'>" +
                "<h1 style='color:blue;'>这是一个 HTML 页面</h1>" +
                "<p>由 <b>WebView</b> 加载的本地 HTML 字符串</p>" +
                "<img src='https://httpbin.org/image/png' width='150'/>" +
                "<p style='color:gray;'>可以包含图片、样式、JS 等内容</p>" +
                "</body></html>";

        // 加载 HTML 数据
        webView.loadDataWithBaseURL(null, htmlData, "text/html", "UTF-8", null);
    }
}